package org.dream.util;

import java.util.HashMap;
import java.util.Map;

import javax.swing.JTextArea;

public class LogImpl implements Log {
	private Map<String, Long> startTimes = new HashMap<String, Long>();
	private Map<String, JTextArea> processViews = new HashMap<String, JTextArea>();

	public void startLogTime(String id) {
		startTimes.put(id, System.currentTimeMillis());

	}

	public long endLongTime(String id) {
		long startTime = startTimes.get(id);
		long times = System.currentTimeMillis() - startTime;
		startTimes.remove(id);
		System.out.println(id + ":" + times);
		return times;
	}

	public void logSql(String sql) {
		System.out.println(sql);

	}

	public void logError(String errStr) {
		System.out.println("logError:" + errStr);

	}

	public void registerProcessView(String id, JTextArea jTextArea) {
		processViews.put(id, jTextArea);
	}

	public void logProcess(String id, String process) {
		if (null != processViews.get(id)) {
			processViews.get(id).setText(
					process + System.getProperty("line.separator") + processViews.get(id).getText());
		}

	}

	public static void main(String[] args) {

	}
}
